package com.aaa.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.lang.String;
import java.util.Collection;
import java.util.Date;

@Data
@TableName("emp")
public class Emp implements UserDetails {
@TableId(value = "eid",type = IdType.AUTO)
  private Integer eid;
  private String ename;
  private String eusername;
  private String epass;
  private String sex;
    @JsonFormat(  pattern="yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
  private Date hiredate;
    @JsonFormat(  pattern="yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
  private Date leavedate;
  private String tel;
  private Integer roleid;
  private String idcard;
  private Integer state;
  private String photo;
  private Integer authstate;

  @TableField(exist = false)
  private Role role;

    @TableField(exist = false)//该字段不使用
    private Collection authorities;

    public void setAuthorities(final Collection authorities) {
        this.authorities = authorities;
    }

    //获取权限
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }
    //获取密码
    @Override
    public String getPassword() {
        return this.epass;
    }
    //获取密码
    @Override
    public String getUsername() {
        return this.eusername;
    }
    //用户是否过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    //用户是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    // 凭证是否过期:密码
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
//用户是否禁用
    @Override
    public boolean isEnabled() {
        return this.getState()==1?true:false;
    }
}
